<?php
namespace app\admin\controller\manage;
use \app\common\Common;
use app\common\service\StaffService;
use think\Request;
use \app\admin\model\Staff as staffModel;

class Staff extends Common
{
    public static function staffList(Request $request)
    {
        $search = $request->param("search","");
        $staffName = $request->param("staff_name","");
        $page = $request->param("page",0);
        $limit = $request->param("limit",10);
        $mobile = $request->param("mobile",'');
        $dutyId = $request->param("duty_id",0);
        $mobile = $request->param("mobile",0);
        $teamId = $request->param("team_id","");
        $staffNo = $request->param("staff_no",0);
        $onStatus = $request->param("on_status","");
        $list = staffModel::List($search,$staffName,$dutyId,$teamId,$page,$limit,$staffNo,$onStatus,$mobile);
        return successJson("success",$list);
    }

    public static function StaffAllStatus(Request $request)
    {
        $status = $request->param("status");
        $staffId = $request->param("staff_id");
        $resStaff = \app\admin\model\Staff::where("id",$staffId)->find();
        if($resStaff["on_status"] == $status){
            return failedJson("状态相同~");
        }
        $res = staffModel::onStatusSet($staffId,$status);
        if($res)return failedJson($res);
        // 状态 1 上班 0 下班
        $in = "";
        $out = "";
        if($status == 1){
            $in = $resStaff["staff_no"];
        }else{
            $out = $resStaff["staff_no"];
        }
        // 列表进出
        staffModel::allocStaff($in,$out,"af");
        return successJson("success","成功");
    }


    /**
     * 客服在线列表
     */
    public static function staffOnlineList(Request $request)
    {
        $data = $request->only(['page', 'limit']);
        $list = (new StaffService())->StaffOnlineList($data);
        return successJson('客服在线列表返回成功', $list);
    }

    public static function getOnStatus(){

        return successJson("success",[
            ["id" => 1,"name" => "上班"],
            ["id" => 0,"name" => "休息"],
            ["id" => -1,"name" => "离职"],
        ]);

    }
}